﻿/*********************************************************
*	xyd function (jquery)
*********************************************************/

$(function(){

/********************************************************
*	ace start
********************************************************/

	//固定顶部、左侧、菜单栏
	xyd.ace.setSidebarPosition = function(){
		var box = $('#ace-settings-container');
		box.find(".ace-settings-item").find("input[type='checkbox']").each(function(index){
			if(index<3){
				$(this).click();
			}
		});
	}
	
	
/********************************************************
*	xyd function start
********************************************************/
	
	
	/****************************************
	*	初始化检测
	****************************************/
	xyd.fn.init = function(){
		xyd.fn.isSupportSvg();
		xyd.fn.getBrowser();
	}
	
	/****************************************
	*	生成uuid
	****************************************/
	xyd.fn.createUUID = function(){
		var d = new Date().getTime();
		var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
		  var r = (d + Math.random()*16)%16 | 0;
		  d = Math.floor(d/16);
		  return (c=='x' ? r : (r&0x3|0x8)).toString(16);
		});
		return uuid;
	}
	
	/****************************************
	*	判断数据类型
	*		type:
	*		object Undefined],[object Null],[object String],[object Number]
	*		[object Array],[object Date],[object Function]
	****************************************/
	xyd.fn.geteTypeof = function(b){
		var base = Object.prototype.toString.call(b).toLocaleLowerCase();
		return base.replace(/(^\[object\s*)(.*)(\]$)/,"$2");
	}
	
	
	/****************************************
	*	加载javaScript文件
	****************************************/
	xyd.fn.scriptToText = function(s){
		var html = "";
		try{
			var j = s;
			for(i in jsList){
				htmlScript += "<script src=\""+j[i]+'?v='+new Date().getTime()+"\"></script>";
			}
		}catch(e){}
		return html;
	};
	
	/****************************************
	*	检测浏览器信息
	****************************************/
	xyd.fn.getBrowser = function(){
		 var Sys = {};
	     var ua = navigator.userAgent.toLowerCase();
	     var re =/(msie|firefox|chrome|opera|version).*?([\d.]+)/;
	     var m = ua.match(re);
		 Sys.info = ua;
	     Sys.browser = m[1].replace(/version/, "'safari");
	     Sys.ver = m[2];
	     return Sys;
	}

	/****************************************
	*	检测是否支持SVG标签
	****************************************/
	xyd.fn.isSupportSvg = function(){
		var svg = $("<svg></svg>");
		svg.attr("xmlns","http://www.w3.org/2000/svg");
		svg.attr("xmlns:xlink","http://www.w3.org/1999/xlink");
		svg.attr("version","1.1");
	}
	
	/****************************************
	*	检测按键
	****************************************/
	xyd.fn.getKeyup = function(){
		$(document).keydown(function(event){});
	}
	
	/****************************************
	*	设置全屏
	****************************************/
	xyd.fn.setFullscreen = function(){}
	
	/****************************************
	*	异步绑定事件
	****************************************/
	xyd.fn.on = function(eventName,elName,fn){
		$(document.body).on(eventName,elName,function(event){
			return fn();
		});
	}
	xyd.fn.bind = function(eventName,elName,fn){
		xyd.fn.on(eventName,elName,fn);
	}
	
	/****************************************
	*	验证密码强度,123代表弱中强
	****************************************/
	xyd.fn.getPasswordLevel = function(str){
		
		var s = str==undefined ? str="" : str.toString();
		var level = 0;
		if(s.length<6){return level}
		
		var reg = /[0-9]+/igm;
		if(reg.test(s)){level=level+1}
		
		var reg = /[a-z]+/igm;
		if(reg.test(s)){level=level+1}
		
		var reg = /[\.\!@#\$%\^&\*\(\)\[\]\{\}]{1,}/igm;
		if(reg.test(s)){level=level+1}
		return level;
		
	}
	
	
	/****************************************
	*	自定义组件xyd.module
	****************************************/
	
	//模拟开关
	xyd.module.bindButton1 = function(){
		$(document.body).on("click",".button_on",function(event){
			var data = $(this).attr("data-state");
			var p,left = $(this).css("left");
			if(data!=='undefined' && data=="1"){
				p = "-60";
				$(this).attr("data-state","0");
			}else{
				p = "0";
				$(this).attr("data-state","1");
			}
			$(this).animate({"left":p+"px"});
		});
	}
	
	xyd.module.init = function(){
		xyd.module.bindButton1();
	}
	
	
	xyd.module.init();
	
	
});
